package ink.charon.novel.utils;

import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ProxyUtil {
    /*
    * http://api.shenlongip.com/ip?key=e5r8b74g&pattern=json&count=1&need=1000&protocol=1
    * */
    public static String getProxy() {
        return HttpRequest.get("http://api.shenlongip.com/ip?key=e5r8b74g&pattern=json&count=1&need=1000&protocol=1").execute().body();
    }


    public static void main(String[] args) {
        Map res = JSONUtil.parseObj(getProxy()).toBean(Map.class);
        Integer code = (Integer) res.get("code");
        List<Map<String, Object>> data = (List<Map<String, Object>>) res.get("data");
        Map<String, Object> dataMap = data.get(0);
        String ip = (String) dataMap.get("ip");
        Integer port = (Integer) dataMap.get("port");
        System.out.println("code = " + code);
        System.out.println("ip = " + ip);
        System.out.println("port = " + port);
    }
}
